package entity

import (
	"strconv"
	"time"

	"shqsoft.cn/pasnj/base"
	"shqsoft.cn/pasnj/bi/cube"
)

type CM_IBANK_CUST_BIZ_SUM_M struct {
	ID   int        `gorm:"AUTO_INCREMENT;primary_key;column:JLID"`
	SJRQ *time.Time `gorm:"column:DATA_DT;type:date;"`
	KHMC string     `gorm:"column:CUST_NAME"`
	ZHMC string     `gorm:"column:ACCT_NAME"`
	KHH  string     `gorm:"column:CUST_NUM"`
	ZZJG string     `gorm:"column:ORG_ORG_CD"`
	Qxr  *time.Time `gorm:"column:START_INT_DT;type:date;"`
	Dqr  *time.Time `gorm:"column:MATURE_DT;type:date;"`
	Khr  *time.Time `gorm:"column:OPEN_DT;type:date;"`
	Xhr  *time.Time `gorm:"column:CLOSE_DT;type:date;"`
	CYNM string     `gorm:"column:CYNM;"`
	UTNM string     `gorm:"column:UTNM;"`
	INRT *float64   `gorm:"column:EXEC_INT_RATE;"`
	ACBL *float64   `gorm:"column:CURR_BAL;"`
	YJLX *float64   `gorm:"column:ACCRUED_INT;"`
	Ckqx *float64   `gorm:"column:DPSIT_TERM;"`
	Cpbh string     `gorm:"column:PROD_NUM;"`
	Khzh string     `gorm:"column:CUST_ACC_NUM"`
	FTP  *float64   `gorm:"column:FTP"`
	ITNM string     `gorm:"column:ITNM"`
	STTP int        `gorm:"column:STTP"`
	CUID int        `gorm:"column:CUID"`
	YG1  string     `gorm:"-"`
	ZB1  *float64   `gorm:"-"`
	YG2  string     `gorm:"-"`
	ZB2  *float64   `gorm:"-"`
	YG3  string     `gorm:"-"`
	ZB3  *float64   `gorm:"-"`
	YG4  string     `gorm:"-"`
	ZB4  *float64   `gorm:"-"`
	YG5  string     `gorm:"-"`
	ZB5  *float64   `gorm:"-"`
}

//TableName 表名同业
func (CM_IBANK_CUST_BIZ_SUM_M) TableName() string {
	return "V_CM_IBANK_CUST_BIZ_SUM_M"

}

func (c *CM_IBANK_CUST_BIZ_SUM_M) AfterFind() (err error) {
	var share *cube.Share
	share, err = cube.GetShare("comp_qtzb_divi")
	if err != nil {
		return
	}
	var diviMap map[string]float64
	diviMap, err = share.GetDivision("13:" + strconv.Itoa(c.ID))
	if err != nil {
		return
	}
	i := 0
	if diviMap == nil || len(diviMap) == 0 {
		share, err = cube.GetShare("comp_clie_divi")
		if err != nil {
			return
		}
		diviMap, err = share.GetDivision(strconv.Itoa(c.CUID))
		if err != nil {
			return
		}
	}
	for k, v := range diviMap {
		val := v
		i++
		switch i {
		case 1:
			c.YG1 = k
			c.ZB1 = &val
		case 2:
			c.YG2 = k
			c.ZB2 = &val
		case 3:
			c.YG3 = k
			c.ZB3 = &val
		case 4:
			c.YG4 = k
			c.ZB4 = &val
		case 5:
			c.YG5 = k
			c.ZB5 = &val
		default:
			break
		}
	}
	return
}

//CM_IBANK_CUST_BIZ_SUM_M 同业
func CM_IBANK_CUST_BIZ_SUM_MEF() base.EntityFunc {
	return func() interface{} {
		entity := CM_IBANK_CUST_BIZ_SUM_M{}
		return &entity
	}
}

//CM_IBANK_CUST_BIZ_SUM_M 同业
func CM_IBANK_CUST_BIZ_SUM_MESF() base.EntitiesFunc {
	return func() interface{} {
		var entities []CM_IBANK_CUST_BIZ_SUM_M
		return &entities
	}
}
func init() {
	dao := base.NewDefaultDao(CM_IBANK_CUST_BIZ_SUM_MEF(), CM_IBANK_CUST_BIZ_SUM_MESF(), nil)
	// filter := base.DefaultFilter{
	// 	FilterColName: "JLID",
	// 	TableName:     "T_COMP_QTZB_DIVI",
	// 	EmidColName:   "emid",
	// 	AcidColName:   "JLID",
	// 	WhereCause:    "YWID=13",
	// }
	// dao.Fileter = &filter
	base.DaoPoolObj.Put("CM_IBANK_CUST_BIZ_SUM_M", dao)
}
